import { App } from 'vue'
import { useIntersectionObserver } from '@vueuse/core'
export default {
  install (app: App) {
    app.directive('lazyImg', {
      mounted (dom, obj) {
        const { stop } = useIntersectionObserver(
          dom,
          ([{ isIntersecting }]) => {
            if (isIntersecting) {
              dom.src = obj.value
              stop()
            }
          },
          {
            threshold: 0
          }
        )
      }
    })
  }
}
